@bpv(NQP)@              = nqp@moar::exe@
@bpv(NQP_M)@            = nqp-m@moar::exe@
@bpv(BUILD_RUNNER)@     = nqp-m@moar::exe@
@bpv(BUILD_RUNNER_BIN)@ = @nfp($(BASE_DIR)/@bpm(BUILD_RUNNER)@)@
@bpv(INST_NQP)@			= inst-nqp@moar::exe@
@bpv(INST_NQP_M)@		= inst-nqp-m@moar::exe@
@bsv(NQP_LIB_DIR)@		= $(NQP_LIB_DIR)
# It's ok to shell quote this one as it only used in a command line

@bpv(MOAR_INC_PATHS)@ = \
  @moar::cincludes@ \
  @moar::ccinc@@nfpq(@moar::prefix@/include)@ \
  @moar::ccinc@@nfpq(@moar::prefix@/include/moar)@ \
  @moar::ccinc@@nfpq(@moar::prefix@/include/libatomic_ops)@ \
  @moar::ccinc@@nfpq(@moar::prefix@/include/dyncall)@ \
  @moar::ccinc@@nfpq(@moar::prefix@/include/moar)@ \
  @moar::ccinc@@nfpq(@moar::prefix@/include/sha1)@ \
  @moar::ccinc@@nfpq(@moar::prefix@/include/tinymt)@ \
  @moar::ccinc@@nfpq(@moar::prefix@/include/libtommath)@ \
  @moar::ccinc@@nfpq(@moar::prefix@/include/libuv)@

@for_stages(@bpv(@ucstage@_GEN_CAT)@ = @bpm(GEN_CAT)@ @lcstage@
)@

@bpv(STAGE0_NQP)@ = @q(@moar@)@ --libpath=@bpm(STAGE0_DIR)@ @nfp(@bpm(STAGE0_DIR)@/nqp.@bext@)@ --bootstrap
@bpv(STAGE1_NQP)@ = @q(@moar@)@ --libpath=@bpm(STAGE1_DIR)@ @nfp(@bpm(STAGE1_DIR)@/nqp.@bext@)@ --bootstrap

@bsv(ASTOPS)@   		= MASTOps.@bext@
@bpv(ASTOPS_SOURCES)@	= @nfp(@moar_prefix@/share/nqp/lib/MAST/Ops.nqp)@
@bpv(ASTNODES_SOURCES)@	= @nfp(@moar_prefix@/share/nqp/lib/MAST/Nodes.nqp)@

@bpv(NQP_SOURCES_EXTRA)@ = @nfp(src/vm/@backend@/NQP/Ops.nqp)@

@bpv(EXTRA_TESTS)@ = @nfp(t/concurrency)@

@include(Makefile-backend-common)@

@backend_prefix@-all:: @bpm(INST_NQP_M)@ @bpm(INST_NQP)@

@backend_prefix@-install-dirs::
	$(NOECHO)$(MKPATH) @nfpq($(DESTDIR)$(NQP_LIB_DIR)/profiler)@

@backend_prefix@-install::
	@echo(+++ Installing @uc(@backend@)@ specifics)@
	$(NOECHO)$(CP) @bsm(ASTOPS)@ @q($(DESTDIR)$(NQP_LIB_DIR))@
	$(NOECHO)$(CP) @nfp(src/vm/moar/profiler/template.html)@ @nfpq($(DESTDIR)$(NQP_LIB_DIR)/profiler/template.html)@
	$(NOECHO)$(CP) @bpm(INST_NQP_M)@ @nfpq($(DESTDIR)$(BIN_DIR)/@bpm(NQP_M)@)@
@expand(@m_install@)@

# FIXME:
@bpv(CLEANUPS_EXTRA)@ = \
  nqpmc \
  nqp-m.c \
  nqp-m@moar::obj@ \
  nqp.c \
  nqp@moar::obj@ \
  inst-nqp-m@moar::obj@ \
  @bpm(INST_NQP_M)@ \
  inst-nqp@moar::obj@ \
  @bpm(INST_NQP)@

@bpv(CC_INST_NQP)@=@moar::cc@ @moar::ccswitch@ @moar::cflags@ @static_nqp_home_define@ @bpm(MOAR_INC_PATHS)@
@bpv(LD_INST_NQP)@=@moar::ld@ @ldflags@ @mingw_unicode@
@bpv(LD_INST_NQP_POST)@=@moar::lddir@"@moar::libdir@" @c_runner_libs@ @moar_lib@

@bpv(CC_BUILD_RUNNER)@=@moar::cc@ @moar::ccswitch@ @moar::cflags@
@bpv(LD_BUILD_RUNNER)@=@moar::ld@ @ldflags@ @mingw_unicode@

@bpm(INST_NQP)@: @nfp(src/vm/moar/runner/main.c)@
	@echo(+++ Compiling	$@)@
	$(NOECHO)$(RM_F) $@
# Using only the pkgconfig moar includes does not work, because moar.h assumes all the specific includes below.
	$(NOECHO)@bpm(CC_INST_NQP)@ @if(relocatable -DSTATIC_EXEC_PATH=@q(@c_escape(@nfp(@prefix@/bin/@bpm(NQP)@)@)@)@)@ @moar::ccout@inst-nqp@moar::obj@ @nfp(src/vm/moar/runner/main.c)@
	$(NOECHO)@bpm(LD_INST_NQP)@ @moar::ldout@$@ inst-nqp@moar::obj@ @bpm(LD_INST_NQP_POST)@

@bpm(INST_NQP_M)@: @nfp(src/vm/moar/runner/main.c)@
	@echo(+++ Compiling	$@)@
	$(NOECHO)$(RM_F) $@
# Using only the pkgconfig moar includes does not work, because moar.h assumes all the specific includes below.
	$(NOECHO)@bpm(CC_INST_NQP)@ @if(relocatable -DSTATIC_EXEC_PATH=@q(@c_escape(@nfp(@prefix@/bin/@bpm(NQP_M)@)@)@)@)@ @moar::ccout@inst-nqp-m@moar::obj@ @nfp(src/vm/moar/runner/main.c)@
	$(NOECHO)@bpm(LD_INST_NQP)@ @moar::ldout@$@ inst-nqp-m@moar::obj@ @bpm(LD_INST_NQP_POST)@

@bpm(BUILD_RUNNER)@: @@configure_script@@ @@template(@platform@/nqp-m-build.c)@@
	@echo(+++ Setting up	$@)@
	$(NOECHO)$(RM_F) @q(@bpm(BUILD_RUNNER)@)@
	$(NOECHO)$(CONFIGURE) --expand @@template(@platform@/nqp-m-build.c)@@ --out nqp-m.c \
		--set-var=MOAR=@shquot(@nfp(@moar@)@)@ \
		--set-var=base_dir=@shquot(@nfp($(BASE_DIR))@)@  \
		--set-var=exec_name=@shquot(@nfp($(BASE_DIR)/@bpm(BUILD_RUNNER)@)@)@ \
		--set-var=mbc=@bsm(NQP)@
	$(NOECHO)@bpm(CC_BUILD_RUNNER)@ @moar::ccout@nqp-m@moar::obj@ nqp-m.c
	$(NOECHO)@bpm(LD_BUILD_RUNNER)@ @moar::ldout@$@ nqp-m@moar::obj@

@backend_prefix@-runner-default: @backend_prefix@-all @@configure_script@@ @@template(@platform@/nqp-m-build.c)@@
	@echo(+++ Compiling @uc(@backend@)@ default runner)@
	$(NOECHO)$(RM_F) @q(@bpm(NQP)@)@
	$(NOECHO)$(CONFIGURE) --expand @@template(@platform@/nqp-m-build.c)@@ --out nqp.c \
		--set-var=MOAR=@shquot(@nfp(@moar@)@)@ \
		--set-var=base_dir=@shquot(@nfp($(BASE_DIR))@)@  \
		--set-var=exec_name=@shquot(@nfp($(BASE_DIR)/@bpm(NQP)@)@)@ \
		--set-var=mbc=@bsm(NQP)@
	$(NOECHO)@bpm(CC_BUILD_RUNNER)@ @moar::ccout@nqp@moar::obj@ nqp.c
	$(NOECHO)@bpm(LD_BUILD_RUNNER)@ @moar::ldout@@bpm(NQP)@ nqp-m@moar::obj@

@backend_prefix@-runner-default-install: @backend_prefix@-runner-default @backend_prefix@-install
	@echo(+++ Installing default runner)@
	$(NOECHO)$(CP) @bpm(INST_NQP)@ @nfpq($(DESTDIR)$(BIN_DIR)/@bpm(NQP)@)@

# vim: ft=make noexpandtab ts=4 sw=4
